// 封装本地存储
// User通用key
const key = 'vue-mobile-shop.userInfo'
// 搜索历史记录
const historyKey = 'vue-mobile-shop.history'

// 获取信息
export const getInfo = () => {
  const emptyValue = { token: '', userId: '' }
  const result = localStorage.getItem(key)
  return result ? JSON.parse(result) : emptyValue
}

// 设置信息
export const setInfo = (user) => {
  localStorage.setItem(key, JSON.stringify(user))
}

export const removeInfo = () => {
  localStorage.removeItem(key)
}

// 获取搜索历史信息
export const getHistory = () => {
  const emptyValue = []
  const result = localStorage.getItem(historyKey)
  return result ? JSON.parse(result) : emptyValue
}

// 设置搜索历史信息
export const setHistory = (history) => {
  localStorage.setItem(historyKey, JSON.stringify(history))
}
